package com.cn.kabalifemerchants.callback;

import android.app.Activity;
import android.content.Context;

import com.cn.kabalifemerchants.base.MyApplication;
import com.cn.kabalifemerchants.utils.NetWorkUtil;
import com.cn.kabalifemerchants.utils.RxToast;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;

import okhttp3.Call;

/**
 * Created by Administrator on 2017/9/11.
 * function：
 */

public class CacheCallBack<T> extends DialogCallback<T> {


    public CacheCallBack() {

        super(null);
    }

    public CacheCallBack(Activity activity) {
        super(activity);
    }

    public CacheCallBack(Activity activity, boolean isLoading) {
        super(activity, isLoading);
    }

    public CacheCallBack(Activity activity, boolean isLoading, String tip) {
        super(activity, isLoading, tip);
    }

    public CacheCallBack(Context context, boolean isLoading) {
        super((Activity) context, isLoading);
    }

    @Override
    public void onStart(Request<T, ? extends Request> request) {
        super.onStart(request);
        int netWork = NetWorkUtil.getAPNType(MyApplication.getContext());
        if (netWork == 0) {
            RxToast.error("当前暂无网络...");
        }
    }

    @Override
    public void onCacheSuccess(Response<T> response) {
        Call call = response.getRawCall();
//        LoggerUtils.v("请求成功  是否来自缓存：true  请求方式：" + call.request().method() + "\n" + "url：" + call.request().url()
//                + "\n" + "response: " + response.body().toString());
    }

    @Override
    public void onError(Response<T> response) {
        Call call = response.getRawCall();
//        LoggerUtils.e("请求失败  是否来自缓存：false  请求方式：" + call.request().method() + "\n" + "url：" + call.request().url()
//                + "\n" + "response: " + response.toString() + "\n" + response.headers());
    }

    @Override
    public void onSuccess(Response<T> response) {
        Call call = response.getRawCall();
//        LoggerUtils.e("请求成功  是否来自缓存：false  请求方式：" + call.request().method() + "\n" + "url：" + call.request().url()
//                + "\n" + "response: " + response.body().toString());
    }
}